//自定义布局的列表输出
package com.xxz.course;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;

import java.util.List;

public class RateListActivity extends AppCompatActivity {
private Handler handler;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rate_list);
        ListView mylist = findViewById(R.id.mylistview);//需要自己加载页面布局

        handler = new Handler(Looper.myLooper()) {
            @Override
            public  void handleMessage(@NonNull Message msg){
                if(msg.what==5){
                    List<String> list = (List<String>) msg.obj;
                    ListAdapter adapter = new ArrayAdapter<String>(RateListActivity.this, android.R.layout.simple_list_item_1,list);
                    mylist.setAdapter(adapter);
                }
                super.handleMessage(msg);
            }
        };

        MyTask mytask = new MyTask();//MyTask为自建类，封装了子线程run事件处理方法
        mytask.setHandler(handler);

        Thread t = new Thread(mytask);
        t.start();
    }
}
